define(["jquery"],function($){
    function Common(){
        this.load();
        // this.loadUser();
    }
    Common.prototype = {
        load: function(){
            $.get("/html/include/header.html",$.proxy(this.loadHeader,this))
                .done($.get("/html/include/fixleft.html",$.proxy(this.loadFixLeft,this)));
        },

        addListener: function(){
            $(".list1").on("click",function(){ location.href="/html/billmanage.html";});
            $(".list3").on("click",function(){ location.href="/html/usermanage.html";});
            $(".btn-logout").on("click",$.proxy(this.logoutHandler,this));
        },
        loadHeader: function(data){
            $(".header").html(data);
        },

        loadFixLeft: function(data){
            $(".fixleft").html(data);
            this.addListener();
            this.loadUser();
        },
        loadUser:function(){
            const user = sessionStorage.username;
            // console.log($(".loginusername"));
            if(user){
                $(".loginusername").text(user).parents(".out").removeClass("hidden").siblings(".in").addClass("hidden");
            }
        },
        logoutHandler: function(){
            const url = "/api/users/logout";
            $.get(url,function(data){
                if(data.res_body.status === 1){
                    sessionStorage.removeItem("username");
                    location.reload();
                }
            },"json")

            return false;
        }

        
    }

    new Common();
})